﻿namespace WorkOrder.Business
{
    public class UnitTotal
    {
        DbHelper dbhelper = new DbHelper();
        public System.Data.DataTable getUnit(string table)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name  as 单位 from Table_Integrated_unit";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name  as 单位 from Table_Debugging_unit";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name  as 单位 from Table_Supervision_unit";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

        //计划
        public System.Data.DataTable getPlan(string table,string startTime,string endTime,string productID)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name,count(order_number) as Num from Table_Changeover A,Table_Integrated_unit B " +
                    "where product_id=" + productID + " and first_cute_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.inte_unit_id=B.inte_unit_id group by inte_unit_name;";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name,count(order_number) as Num from Table_Changeover A,Table_Debugging_unit B " +
                    "where product_id=" + productID + " and first_cute_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.debug_unit_id=B.debug_unit_id group by debug_unit_name;";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name,count(order_number) as Num from Table_Changeover A,Table_Supervision_unit B " +
                    "where product_id=" + productID + " and first_cute_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.supe_unit_id=B.supe_unit_id group by supe_unit_name;";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

        //试通
        public System.Data.DataTable getTry(string table, string startTime, string endTime, string productID)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name,count(order_number) as Num from Table_Changeover A,Table_Integrated_unit B " +
                    "where product_id=" + productID + " and try_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.inte_unit_id=B.inte_unit_id group by inte_unit_name;";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name,count(order_number) as Num from Table_Changeover A,Table_Debugging_unit B " +
                    "where product_id=" + productID + " and try_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.debug_unit_id=B.debug_unit_id group by debug_unit_name;";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name,count(order_number) as Num from Table_Changeover A,Table_Supervision_unit B " +
                    "where product_id=" + productID + " and try_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.supe_unit_id=B.supe_unit_id group by supe_unit_name;";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

        //软调
        public System.Data.DataTable getDebug(string table, string startTime, string endTime, string productID)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name,count(order_number) as Num from Table_Changeover A,Table_Integrated_unit B " +
                    "where product_id=" + productID + " and debugging_confirm_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.inte_unit_id=B.inte_unit_id group by inte_unit_name;";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name,count(order_number) as Num from Table_Changeover A,Table_Debugging_unit B " +
                    "where product_id=" + productID + " and debugging_confirm_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.debug_unit_id=B.debug_unit_id group by debug_unit_name;";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name,count(order_number) as Num from Table_Changeover A,Table_Supervision_unit B " +
                    "where product_id=" + productID + " and debugging_confirm_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.supe_unit_id=B.supe_unit_id group by supe_unit_name;";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

        //拨测
        public System.Data.DataTable getTest(string table, string startTime, string endTime, string productID)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name,count(order_number) as Num from Table_Changeover A,Table_Integrated_unit B " +
                    "where product_id=" + productID + " and test_confirm_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.inte_unit_id=B.inte_unit_id group by inte_unit_name;";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name,count(order_number) as Num from Table_Changeover A,Table_Debugging_unit B " +
                    "where product_id=" + productID + " and test_confirm_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.debug_unit_id=B.debug_unit_id group by debug_unit_name;";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name,count(order_number) as Num from Table_Changeover A,Table_Supervision_unit B " +
                    "where product_id=" + productID + " and test_confirm_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.supe_unit_id=B.supe_unit_id group by supe_unit_name;";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

        //交付
        public System.Data.DataTable getDelivery(string table, string startTime, string endTime, string productID)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name,count(order_number) as Num from Table_Changeover A,Table_Integrated_unit B " +
                    "where product_id=" + productID + " and delivery_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.inte_unit_id=B.inte_unit_id group by inte_unit_name;";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name,count(order_number) as Num from Table_Changeover A,Table_Debugging_unit B " +
                    "where product_id=" + productID + " and delivery_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.debug_unit_id=B.debug_unit_id group by debug_unit_name;";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name,count(order_number) as Num from Table_Changeover A,Table_Supervision_unit B " +
                    "where product_id=" + productID + " and delivery_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.supe_unit_id=B.supe_unit_id group by supe_unit_name;";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

        //回访
        public System.Data.DataTable getReturnVisit(string table, string startTime, string endTime, string productID)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name,count(order_number) as Num from Table_Changeover A,Table_Integrated_unit B " +
                    "where product_id=" + productID + " and return_visit_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.inte_unit_id=B.inte_unit_id group by inte_unit_name;";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name,count(order_number) as Num from Table_Changeover A,Table_Debugging_unit B " +
                    "where product_id=" + productID + " and return_visit_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.debug_unit_id=B.debug_unit_id group by debug_unit_name;";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name,count(order_number) as Num from Table_Changeover A,Table_Supervision_unit B " +
                    "where product_id=" + productID + " and return_visit_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' and " +
                    "A.supe_unit_id=B.supe_unit_id group by supe_unit_name;";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

        //计划+试通
        public System.Data.DataTable getPlanAndTry(string table, string startTime, string endTime, string productID)
        {
            string sqlstr = "";
            if (table == "Table_Integrated_unit")
                sqlstr = "select inte_unit_name,count(order_number) as Num from Table_Changeover A,Table_Integrated_unit B " +
                    "where product_id=" + productID + " and (first_cute_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' or " +
                    "try_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59') and " +
                    "A.inte_unit_id=B.inte_unit_id group by inte_unit_name;";
            if (table == "Table_Debugging_unit")
                sqlstr = "select debug_unit_name,count(order_number) as Num from Table_Changeover A,Table_Debugging_unit B " +
                    "where product_id=" + productID + " and (first_cute_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' or " +
                    "try_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59') and " +
                    "A.debug_unit_id=B.debug_unit_id group by debug_unit_name;";
            if (table == "Table_Supervision_unit")
                sqlstr = "select supe_unit_name,count(order_number) as Num from Table_Changeover A,Table_Supervision_unit B " +
                    "where product_id=" + productID + " and (first_cute_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59' or " +
                    "try_time between '" + startTime + " 0:0:0' and '" + endTime + " 23:59:59') and " +
                    "A.supe_unit_id=B.supe_unit_id group by supe_unit_name;";
            if (sqlstr != "")
                return dbhelper.Query(sqlstr).Tables[0];
            else
                return null;
        }

    }
}
